<template>
    <div>
        <h1>登录界面</h1>
        用户名：<Input id="name"/><br/>
        密码：<Input id="pwd"/><br/>
        <button @click="login">登录</button>
    </div>
</template>

<script>
    export default {
        methods: {
            login () {
				var n = document.getElementById("name").value;
				var p = document.getElementById("pwd").value;
                //this.$router.replace('/')
				this.$axios({
				method: 'post',
				url: 'http://localhost:8181/login',
				params:{
					name:n,
					password:p
				},
				})
				.then((response) => {
					//alert(response.data.name);
					//alert(response.data.name+response.data.password);
					if(response.data.name != null){   
						//this.$router.push('/'); // 此处因为ES6箭头函数上下文穿透，this的上下文为外层的this，即Vue实例
						this.$router.push({
							name:'Success',
							params:
							{	name:response.data.name,
								password:response.data.password
							}
						})  //带着参数跳转					
					}
				})
				.catch(function (error) {
				console.log(error)
				alert("登录失败");
				//alert(error)
				})
            }
        }
    }
</script>
